#ifndef MESSAGEPAGESTYLE_H
#define MESSAGEPAGESTYLE_H

#include <QWidget>
#include <QLabel>
#include <QCheckBox>
#include <QRadioButton>
#include <QVBoxLayout>
#include <QPushButton>
#include <QComboBox>
#include <QTextEdit>
#include <QFileDialog>
#include <QDialog>
#include <QDebug>
#include <QFile>
#include <sys/utsname.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <QProcess>
#include <fstream>
#include <iostream>
#include <cstring>
#include <QFileInfo>
#include <QListWidget>
#include <QTimer>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
#include <QGraphicsDropShadowEffect>
#include <QStandardPaths>
#include <QEventLoop>
#include <QStyledItemDelegate>
#include <QEvent>
#include <QThread>
#include <QGSettings>

#include "file_item_init.h"
#include "widget_parameter_class.h"
#include "systeminfo_button.h"
#include "my_combobox.h"
#include "my_qlineedit.h"
#include "smtpMailClient.h"
#include "submitBase.h"

#define THEME_GSETTINGS "org.ukui.style"
#define THEME_HIGH_COLOR "theme-color"

namespace Ui {
class MessagePageStyle;
}

using namespace std;

class MessagePageStyle : public QWidget
{
    Q_OBJECT

public:
    explicit MessagePageStyle(QWidget *parent = nullptr);
    ~MessagePageStyle();
    void changeFont(QFont curFont);
    void changePageForTheme(const QString& str);
protected:
    void systeminfo_show(QPointF pt);
    void systeminfo_hide();

signals:
    void connectToHost();
    void sendMail(const mailContent& mailContentStruct);

private slots:
    void detailTextEdit_textChanged();
    void styleOfAskCombobox_currentIndexChanged(QString str);
    void commitButtonPressed();
    void on_resetButton_clicked();
    void mailTextEditFoucusOut();
    void mailTextEdit_textChanged();

public slots:

    void telTextEdit_textChanged();
    void nameTextEdit_textChanged();

    void syslogUpload_stateChanged();

    void userPermission_stateChanged(int);

    void userDataPushButton_clicked();

    void del_file_button_clicked();

    QByteArray get_today_syslog();

    void mailHostConnectResult(int connectRes);

    void mailSendResult(int sendRes);


private:
    void uiInit();
    void pageStyleOfAskRowLocationInit();
    void pageContentOfAskRowLocationInit();
    void pageUploadFilesRowLocationInit();
    void pageSysLogRowLocationInit();
    void pageMailRowLocationInit();
    void pageTelRowLocationInit();
    void pageSysInfoLocationInit();

    bool allFileSizeLargerThan10M();
    bool commitButtonStyleSet();
    void set_all_disable_in_submit();

    void addFileInfoModel();

    void update_add_file_window();

    void getSysteminfo();

    void set_all_enable_after_submit();

    void uploadFile_afterButtonClicked();

    void removeUploadFileNameListFile(QPushButton* btn);

    void getCodingFormat();
    void getSysVersion();
    void getDesktopInfo();

    QTimer *m_submittingTimer = nullptr;

    QString m_textStyleOfAsk = "系统问题";

    QString m_detailText = "";
    QString m_mailText = "";
    QString m_telText = "";
    QString m_nameText = "";

    QString m_userUploadFileName;
    QList<QString> m_uploadFileNameList;
    QList<QString> m_uploadFileSizeList;
    QList<QString> m_uploadFilePathList;

    QListWidgetItem * m_fileListWidgetItem[5];
    FileItemInit* m_fileWidget[5];

    Ui::MessagePageStyle *ui;
    bool m_hasDetailText = false;
    bool m_isMailFormat = true;
    bool m_isTelFormat = false;

    bool m_hasGotSyslog = true;
    bool m_hasGotSystemInfo = true;

    //传递系统信息给小弹窗中的字符串
    QString m_sendOsInfo;
    QString m_sendEncodingInfo;
    QString m_sendDekstopInfo;
    QString m_systemInfoStr; //系统版本信息
    QString m_encodingInfoStr; //系统编码格式
    QString m_desktopInfoStr;  //系统桌面环境

    SmtpMailClient *m_eMail;
    QThread *m_pMailThread;
    mailContent m_messageStruct;

    SubmitBase *m_waitDialog = nullptr;
    SubmitBase *m_failDialog = nullptr;
    SubmitBase *m_successDialog = nullptr;

    //显示相关

    QWidget *m_verticalWidget;
    SystemInfoButton *m_showInfoButton;
    QLabel *m_labelSystemVersion_1;
    QLabel *m_labelDesktopVersion_1;
    QLabel *m_labelLanguage_1;
    QLabel *m_labelSystemVersion_2;
    QLabel *m_labelDesktopVersion_2;
    QLabel *m_labelLanguage_2;

    QString m_currentTheme;
    QFont m_smallFont;
    friend class SystemInfoButton;

    QString m_colorName;
};

#endif // MESSAGEPAGESTYLE_H
